import { CopyControllerBase } from "../view/copy/controller/CopyControllerBase";
import { EightyDefenceCopyView } from "../view/copy/eightyDefence/EightyDefenceCopyView";
import { EightyDefenceSkillPanel } from "../view/copy/eightyDefence/EightyDefenceSkillPanel";
import { EightyDefenseCopyConfig } from "../resource/EightyDefenseCopyConfig";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SCopyEightyDefenceInfo } from "../../../Message/Public/SCopyEightyDefenceInfo";
import { SCopyMsgInfo } from "../../../Message/Public/SCopyMsgInfo";
import { ECopyInfoType } from "../../../Message/Public/ECopyInfoType";
import { DataEvent } from "../events/DataEvent";
import { SDefenseUseSkill } from "../../../Message/Public/SDefenseUseSkill";
import { GameProxy } from "../mvc/GameProxy";
import { TCopy } from "../../../Message/Db/Tables/TCopy";
type int = number;
//class EightyDefenceCopyController
    
    export  class EightyDefenceCopyController extends CopyControllerBase
    {
        constructor()
        {
            
            super();this._skillMap = new Map<any, any> /* flash.utils.Dictionary */();
            return;
        }

        public get eightyDefenceCopyView(): EightyDefenceCopyView
        {
            if (this._eightyDefenceCopyView == null) 
            {
                this._eightyDefenceCopyView = new EightyDefenceCopyView();
            }
            return this._eightyDefenceCopyView;
        }

        public get eightyDefenceSkills(): EightyDefenceSkillPanel
        {
            var loc1=0;
            if (this._eightyDefenceSkills == null) 
            {
                loc1 = 5;
                if (copy) 
                {
                    loc1 = EightyDefenseCopyConfig.instance.getSkillNumByCopyCode(copy.code);
                }
                this._eightyDefenceSkills = new EightyDefenceSkillPanel(loc1);
            }
            return this._eightyDefenceSkills;
        }

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicCopyEightyDefeceInfo, this.onCopyEightyDefeceInfoHandler);
            return;
        }

        protected /* override */ addListener(): void
        {
            Dispatcher.addEventListener(EventName.EightyDefenseCopyUseSkill, this.onEightyDefenseCopyUseSkillHandler);
            return;
        }

        protected /* override */ removeListener(): void
        {
            Dispatcher.removeEventListener(EventName.EightyDefenseCopyUseSkill, this.onEightyDefenseCopyUseSkillHandler);
            return;
        }

        /* internal  */onCopyEightyDefeceInfoHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SCopyEightyDefenceInfo;
            this._sCopyEightyDefenceInfo = loc1;
            if (cache.copy.isIn80DefendCopy()) 
            {
                this.eightyDefenceCopyView.updateEightyDefenceInfo(loc1);
                this.eightyDefenceSkills.updateSkillCd(loc1);
            }
            return;
        }

        public updateExp(arg1: int): void
        {
            if (cache.copy.isIn80DefendCopy()) 
            {
                this.eightyDefenceCopyView.updateExp(arg1);
            }
            return;
        }

        public updateRing(arg1: SCopyMsgInfo): void
        {
            if (cache.copy.isIn80DefendCopy() && arg1 && arg1.type.value() == ECopyInfoType._ECopyInfoTypeRing) 
            {
                this.eightyDefenceCopyView.updateRing(arg1);
            }
            return;
        }

        /* internal  */onEightyDefenseCopyUseSkillHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as SDefenseUseSkill;
            if (loc1) 
            {
                GameProxy.copy.useSkillInDefenseCopy(loc1);
            }
            return;
        }

        public /* override */ enterCopy(arg1: TCopy): void
        {
            super.enterCopy(arg1);
            if (cache.copy.isIn80DefendCopy()) 
            {
                if (this._eightyDefenceSkills) 
                {
                    this._eightyDefenceSkills.dispose();
                    this._eightyDefenceSkills = null;
                }
                this.eightyDefenceCopyView.show();
                this.eightyDefenceSkills.show();
                this._skillMap = EightyDefenseCopyConfig.instance.getSkillInfoByCopyCode(arg1.code);
                this.eightyDefenceSkills.updateSkillInfos(this._skillMap);
                if (this._sCopyEightyDefenceInfo) 
                {
                    this.eightyDefenceSkills.updateSkillCd(this._sCopyEightyDefenceInfo);
                }
            }
            return;
        }

        public /* override */ leaveCopy(): void
        {
            super.leaveCopy();
            if (cache.copy.isIn80DefendCopy()) 
            {
                this.eightyDefenceCopyView.hide();
                this.eightyDefenceSkills.hide();
                this._eightyDefenceSkills.dispose();
                this._eightyDefenceSkills = null;
            }
            return;
        }

        public /* override */ stageResize(): void
        {
            if (cache.copy.isIn80DefendCopy()) 
            {
                this.eightyDefenceCopyView.stageResize();
                this.eightyDefenceSkills.stageResize();
            }
            return;
        }

        private /* var */_eightyDefenceCopyView: EightyDefenceCopyView;

        private /* var */_eightyDefenceSkills: EightyDefenceSkillPanel;

        private /* var */_skillMap: Map<any, any> /* flash.utils.Dictionary */;

        private /* var */_sCopyEightyDefenceInfo: SCopyEightyDefenceInfo;
    }
